{layout name="../../admin/view/layout/main" /}
{:breadcrumb(['版本管理(app):version/index/index', '版本列表'])}
{layout name="../../admin/view/layout/main" /}
<div class="card">
    <div class="card-body">
            <div id="toolbar" class="toolbar-btn-action" style="display: flex; flex-direction: row;">
                <button type="button" class="btn btn-success me-1 btn-sm" onclick="add();">
                    <span class="mdi mdi-plus"></span> 新增版本
                </button>
            </div>
            <table id="table"></table>
    </div>
</div>
<div style="height: 1px;"></div>
<div class="modal fade" id="myModal" tabindex="-1" aria-labelledby="exampleModalLiveLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header">
                <h6 class="modal-title" id="exampleModalLiveLabel">版本信息</h6>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form action="{:url('version/index/save')}" method="post" class="input-form needs-validation" novalidate>
                <div class="modal-body">
                    <div class="mb-3 row">
                        <label for="version" class="col-sm-3 col-form-label">版本号 <font color="red">*</font></label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="version" name="version" autocomplete="off" required placeholder="如: 1.0.1">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label for="address" class="col-sm-3 col-form-label">安装包 <font color="red">*</font></label>
                        <div class="col-sm-9 file-group">
                            <div class="input-group">
                                <input type="text" class="form-control file-value" autocomplete="off" name="address" id="address" placeholder="请上传安装包" required/>
                                <div class="input-group-append">
                                  <button class="btn btn-default file-browser" type="button" onclick="selectFile();">上传</button>
                                </div>
                              </div>
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label for="info" class="col-sm-3 col-form-label">版本说明 <font color="red">*</font></label>
                        <div class="col-sm-9">
                            <textarea class="form-control" id="info" name="info" autocomplete="off" required placeholder="输入更新了哪些功能或Bug"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">确定</button>
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var myModal = null;
    var myLayerIndex;
    function add(){
        $('.input-form')[0].reset();
        myModal.show();
    }
    function selectFile(){
        myLayerIndex = open_layer('选择文件', "{:url('attachment/index/index')}?iframe=1&callback=callbackFile", function (){});
    }
    function callbackFile(url){
        $('#address').val(url);
        layer.close(myLayerIndex);
    }
    $(function (){
        myModal = new bootstrap.Modal($('#myModal'));
        validation_form('.input-form', function (){
            myModal.hide();
            $('#table').bootstrapTable('refresh');
        });
        $('#table').bootstrapTable({
          toolbar: '#toolbar',
          classes: 'table table-bordered table-hover table-striped lyear-table',
          url: "{:url('version/index/data')}",
          pagination: 10,
          search: false,
          sidePagination: 'server',
          columns: [
              {'field': 'id', title: 'ID'},
              {'field': 'create_time', title: '创建时间'},
              {'field': 'user', title: '操作员', formatter: function(value, item){
                  return value ? value.nickname : '-';
              }},
              {'field': 'version', title: '版本号'},
              {'field': 'size', title: '大小', formatter: function(value, item){
                return value != 0 ? value : '-';
              }},
              {'field': 'info', title: '版本说明'},
              {'field': 'url', title: '安装包', formatter: function(value, item){
                  return `<a href="${value}" target="_blank">下载</a>`;
              }},
          ]
      });
    });
</script>